<?php
/*
 * 进云智能生成平台
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
 */
defined('BY_JYA') or exit('error');
if($_RQ['corpid']){
	$_AR['wx']=pdo_get('core_account_wxwork',array('uniacid'=>$_SESSION['uniacid'],'appid'=>$_RQ['corpid']),array('id','appid'));	
}
if($_RQ['agentid']){
	$_SESSION['wxworkapp_id']=pdo_getcolumn('core_account_wxwork_app',array('uniacid'=>$_SESSION['uniacid'],'appid'=>$_RQ['agentid']),'id');
}else{
	if(!$_SESSION['wxworkapp_id'] && $_SESSION['current_plugin'] && $_SESSION['current_plugin']!='core'){
			$pid=pdo_getcolumn('core_plugins',array('name'=>$_SESSION['current_plugin']),'id');
			$_SESSION['wxworkapp_id']=pdo_getcolumn('core_account_wxwork_app',array('pid'=>$pid,'uniacid'=>$_SESSION['uniacid']),'id');
	}
}
if(!$_AR['wx']){
	$_AR['wx']=pdo_get('core_account_wxwork',array('uniacid'=>$_SESSION['uniacid'],'isdefault'=>1),array('id','appid','appsecret'));
}
if(!$_AR['wx']){
	$_AR['wx']=pdo_get('core_account_wxwork',array('uniacid'=>$_SESSION['uniacid']),array('id','appid','appsecret'));
}
if($_AR['wx']){//取消此处获取粉丝信息
	$_SESSION['wxwork_id']=$_AR['wx']['id'];
	//如果是普通公众号，就借用系统公众号，如果本公众号获取粉丝失败，也借用
	if($_SESSION['wxwork_id']){
		$_SESSION['after_auth_url']=$_AR['siteurl'];
		if(!$_SESSION['uid']  || $_SESSION['isauth_info']!=1){
			$_SESSION['after_auth_url']=$_AR['siteurl'];
			//不存在openid时，第一次获取openid
			if(!$_SESSION['openid'] && $_SESSION['isauth_base']!=1){
					$url=model('core/member')->wechat_auth_base_url();
					if($url){
						header('location:'.$url);exit;
					}
			}elseif($_SESSION['openid'] && $_SESSION['isauth_info']!=1){//已经有openid时，第一次获取用户信息
					$setting=uni_setting('fans');
					if($setting['type']!=1){
						$url=model('core/member')->wechat_auth_info_url();
						if($url){
							header('location:'.$url);exit;
						}
					}
			}
		}
	}
	//读取jssdk 如果是普通公众号，就借用系统公众号，如果本公众号获取粉丝失败，也借用
	$_AR['jssdk']=cfc('wxwork_userapi')->getJssdkConfig();
	$_AR['jssdk']=ijson_encode($_AR['jssdk']);
	$_AR['share']=array(
			'title'=>$_SESSION['account']['title'],
			'desc'=>$_SESSION['account']['desc'] ? $_SESSION['account']['desc'] : $_SESSION['account']['title'],
			'link'=>$_AR['siteurl'].'&fromuser='.$_SESSION['uid'],
			'imgUrl'=>$_SESSION['account']['logo'] ? tomedia($_SESSION['account']['logo']) : SITEROOT.'core/resource/images/nopic.jpg',
	);
	$_AR['share']=ijson_encode($_AR['share']);
}

